package com.controller;

import com.entity.Client;
import com.entity.PageBean;
import com.entity.Result;
import com.service.ClientService;
import com.vo.ClientVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/client")
public class ClientController {
    @Autowired
    private ClientService clientService;

    @RequestMapping("/getAll/{pageIndex}/{pageSize}")
    private Result getAll(@PathVariable("pageIndex") Integer pageIndex,
                          @PathVariable("pageSize") Integer pageSize,
                          @RequestBody ClientVO clientVO
    ){
        PageBean<Client> pageBean = clientService.getAll(pageIndex, pageSize, clientVO);
        return Result.ok(pageBean);
    }

    @RequestMapping("/getByCid")
    public Result getByCid(Integer cid){
        return Result.ok(clientService.getByCid(cid));
    }

    @RequestMapping("/modify")
    public Result modify(@RequestBody Client client){
        clientService.modify(client);
        return Result.ok();
    }

    @RequestMapping("/remove")
    public Result remove(Integer cid){
        System.out.println(cid);
        clientService.remove(cid);
        return Result.ok();
    }

    @RequestMapping("/getByCname")
    public Result getByCname(String cname){
        return Result.ok(clientService.getByCname(cname));
    }
}
